export function string2buffer(arr) {
  var length = arr.length;
  var buffer = new ArrayBuffer(length);
  var dataview = new DataView(buffer);
  for (let i = 0; i < length; i++) {
    dataview.setUint8(i, Number('0x' + arr[i]));
  }
  return buffer;
}
export const arrayBufferToBase64 = (buffer:  ArrayBuffer) => {
  var binary = '';
  var bytes = new Uint8Array(buffer);
  var len = bytes.byteLength;
  for (var i = 0; i < len; i++) {
      binary += String.fromCharCode(bytes[i]);
  }
  // 对二进制字符串进行base64编码
  return btoa(binary);
}